package server.controller.storeController;

import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.InfoUtils.InfoEnum;
import server.util.InfoUtils.InfoUtil;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addStoreCollection")
public class AddStoreCollectionServlet extends HttpServlet {

    private static final long serialVersionUID = -6351735285596923822L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Info info = null;
        Integer userId = (Integer) req.getAttribute("userId");
        String storeId = req.getParameter("storeId");
        if (storeId == null) {
            info = InfoUtil.getInfo(InfoEnum.PARAMS_NULL);
        } else {
            info = ModelFactory.getJsonIdInUserModel().addObj2User("store_collection",userId, Integer.parseInt(storeId));
        }
        ResponseUtil.responseMessage(resp, info);
    }
}
